package com.garden.framework.exception;

public enum ExceptionCode {
    // 用户相关
    User_Login_UserName_Password_Required("common.user.token.required",101),
    User_Login_Code_Error("user.login.code.error",102),
    User_Login_UserName_Password_Error("user.login.username.password.error",103),
    User_Login_Not_Administrator_Error("user.login.not.administrator.error",103),
    // 公共
    Unknown_Exception("unknown.exception", 100),
    Common_User_Token_Required("common.user.token.required",101),
    Common_User_Token_Authority_Error("common.user.token.authority.error",102),
    Common_Parameter_Required("common.parameter.required",103),
    Common_Qiniu_Token_Error("common.qiniu.token.error",104),

    // 用户相关
    Verify_Code_Used_Or_Timeout("verify.code.used.or.timeout", 201),
    Verify_Code_Error("verify.code.error",202),
    User_Contact_Uploaded_Format_Error("user.contact.upload.format.error", 203),
    User_Contact_Not_Upload("user.contact.upload.not.upload", 204),
    User_Not_Exist("user.not.exist",205),

    // 卡劵相关
    Weixin_Coupon_Not_Exist("weixin.coupon.not.exist", 300),
    Weixin_Coupon_Id_Required("weixin.coupon.id.required", 301),
    Weixin_Coupon_Can_Not_Activated("weixin.coupon.can.not.activated", 302),
    Weixin_Coupon_Can_Not_Used("weixin.coupon.can.not.used", 303),

    // 精选相关
    Merchant_Pick_Exist("merhcant.pick.exist", 601),

    // 微信接口相关
    Weixin_Auth_Denied("weixin.auth.denied",9001),
    Weixin_User_Access_Token_Error("weixin.user.access.token.error",9002),
    Weixin_App_Access_Token_Error("weixin.app.access.token.error",9003),
    Weixin_Login_Openid_Missing("weixin.login.openid.missing",9004),

    Weixin_Menu_Not_Exist("weixin.menu.not.exist",9005),

    File_Upload_fail("file.upload.fail",101),
    ;

    // message code
    private String msgCode;
    // exception code
    private int expCode;

    private ExceptionCode(String msgCode, int expCode) {
        this.msgCode = msgCode;
        this.expCode = expCode;
    }

    public String getMsgCode() {
        return msgCode;
    }
    public int getExpCode() {
        return expCode;
    }

    /**
     * 根据信息编码获取异常编码
     * @param msgCode
     * @return
     */
    public static int valueOfExpCode(String msgCode) {
        int rtnCode = 100;
        ExceptionCode[] exceptionCodes = ExceptionCode.values();
        for(ExceptionCode exceptionCode:exceptionCodes) {
            if(exceptionCode.msgCode.equals(msgCode)) {
                rtnCode = exceptionCode.expCode;
                break;
            }
        }
        return rtnCode;
    }
}
